package com.spider.demo2threadapi;

public class ThreadApiDemo1 {
    public static void main(String[] args) {
        //Thread的常用方法
        Thread t1 = new MyThread("线程一");
        System.out.println(t1.getName());//默认线程名: Thread-索引。
        t1.start();//调用start方法启动线程
        Thread t2 = new MyThread("线程2");
        System.out.println(t2.getName());
        t2.start();

        //获取当前线程
        Thread m = Thread.currentThread();
        m.setName("主线程");
        System.out.println(m.getName());

    }
}
class MyThread extends Thread{
    public MyThread(String name) {
        super( name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"子线程输出：" + i);
        }
    }
}